/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ssp.event;

import java.util.List;
import ssp.net.NWcomponent;
import ssp.net.NWcomponentManager;
import ssp.topology.Node;
import ssp.utility.PropertyManager;

/**
 * ネットワークマップを更新するイベント
 * @author yamazaki
 */
public class NetworkMapUpdateEvent extends Event {
    
    //更新間隔
    private final double t = PropertyManager.getValueAsDouble("NetworkMapUpdateInterval");
    
    /**
     * コンストラクタ
     * @param eventTime イベント時間
     */
    public NetworkMapUpdateEvent(double eventTime) {
        super(eventTime);
    }

    @Override
    public void fire() {
        for(NWcomponent nwComponent : NWcomponentManager.getINSTANCE().getNWcomponentList()) {
            List<Node> neighbors = nwComponent.getNeighborNWcomponents();
            int neighborsSize = neighbors.size();
            for(int i=0 ; i<neighborsSize ; i++) {
                for(int j=i ; j<neighborsSize ; j++) {
                    nwComponent.updateNWmap(neighbors.get(i), neighbors.get(j), this.getEventTime());
                }
            }
        }
        
        if(t >0) {
            EventQueue eventQueue = EventQueue.getINSTANCE();
            eventQueue.addEvent(new NetworkMapUpdateEvent(eventQueue.getCurrentTime() + t));
        }
    }
    
}
